﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;



public partial class Admin_Admin_Rule : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitMenu();
        /*if (!Page.IsPostBack)
        {
            PopulateMenu();
            MenuItem mi1 = new MenuItem();
            MenuItem mi2 = new MenuItem();
            MenuItem mi3 = new MenuItem();
            MenuItem mi4 = new MenuItem();
            MenuItem mi5 = new MenuItem();
            MenuItem mi6 = new MenuItem();
            MenuItem mi7 = new MenuItem();
            MenuItem mi8 = new MenuItem();
            MenuItem mi9 = new MenuItem();

            mi1.Text = "注销此次登陆";
            mi2.Text = "重要通知管理";
            mi3.Text = "校发文件管理";
            mi4.Text = "校策统计";
            mi5.Text = "一周统计";
            mi6.Text = "资源在线";
            mi7.Text = "组织机构";
            mi8.Text = "规章制度";
            mi9.Text = "密码管理";


            // mi2.ChildItems.Add(mi3);
            // mi1.ChildItems.Add(mi2);
            Menu1.Items.Add(mi1);
            Menu1.Items.Add(mi2);
            Menu1.Items.Add(mi3);
            Menu1.Items.Add(mi4);
            Menu1.Items.Add(mi5);
            Menu1.Items.Add(mi6);
            Menu1.Items.Add(mi7);
            Menu1.Items.Add(mi8);
            Menu1.Items.Add(mi9);
            this.Menu1.Orientation = Orientation.Vertical;//设置菜单水平显示
            this.Menu1.StaticDisplayLevels = 1;//只显示第一级菜单
            this.Menu1.Target = "_blank";//指定在新的窗口打开页面
            MenuItem register = new MenuItem();//定义子菜单
            register.Text = "编辑管理";
            register.NavigateUrl = "~/register.aspx";
            this.Menu1.Items[1].ChildItems.Add(register);//添加子菜单

            MenuItem aa = new MenuItem();
            aa.Text = "文件管理";
            aa.NavigateUrl = "~/Login.aspx";
            this.Menu1.Items[1].ChildItems.Add(aa);

            MenuItem Login = new MenuItem();
            Login.Text = "文件类别管理";
            Login.NavigateUrl = "~/Login.aspx";
            this.Menu1.Items[1].ChildItems.Add(Login);

            

            MenuItem help = new MenuItem();//定义第二项菜单的子菜单
            help.Text = "帮助";
            help.NavigateUrl = "~/help.aspx";
            this.Menu1.Items[2].ChildItems.Add(help);
            MenuItem About = new MenuItem();
            About.Text = "关于";
            About.NavigateUrl = "~/About.aspx";
            this.Menu1.Items[2].ChildItems.Add(About);
        }*/


          

       
        //OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        //NewsListGridView.DataSource = from news in dc.News
                                      //join news_category in dc.News_Categories
                                     // on news.News_category equals news_category.Category_id
                                      //where news_category.Category_name.Equals("规章制度")
                                     // orderby news.Time descending
                                     // select new
                                     // {
                                       //   标识 = news.News_id,
                                       //   标题 = news.Title,
                                        //  日期 = news.Time.Value.Month + "-" + news.Time.Value.Day
                                     // };
       // NewsListGridView.DataBind();
        //dc.Dispose();
    }

    protected void InitMenu()
    {

        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        Menu1.Items.Clear();
        MenuItem MainPage = new MenuItem();
        MainPage.Enabled = true;
        MainPage.Selectable = true;
        MainPage.Selected = false;
        MainPage.Value = MainPage.ToolTip = MainPage.Text = "注销此次登陆";
        MainPage.NavigateUrl = "../Default.aspx";
        Menu1.Items.Add(MainPage);

        MenuItem navigation = new MenuItem();
        navigation.Value = navigation.ToolTip = navigation.Text = "页眉管理";
        navigation.NavigateUrl = "../Default.aspx";
        Menu1.Items.Add(navigation);
        
        MenuItem news = new MenuItem();
        news.Value = news.ToolTip = news.Text = "重要通知";
        Menu1.Items.Add(news);

        MenuItem catergory1 = new MenuItem();//定义子菜单
        catergory1.Text = "类别管理";
        catergory1.NavigateUrl = "~/register.aspx";
        Menu1.Items[2].ChildItems.Add(catergory1);//添加子菜单

        MenuItem aa1 = new MenuItem();
        aa1.Text = "重要通知管理";
        aa1.NavigateUrl = "~/Login.aspx";
        Menu1.Items[2].ChildItems.Add(aa1);


        MenuItem document = new MenuItem();
        document.Value = document.ToolTip = document.Text = "校发文件";
        Menu1.Items.Add(document);

        MenuItem catergory2 = new MenuItem();//定义子菜单
        catergory2.Text = "类别管理";
        catergory2.NavigateUrl = "~/register.aspx";
        Menu1.Items[3].ChildItems.Add(catergory2);//添加子菜单

        MenuItem aa2 = new MenuItem();
        aa2.Text = "校发文件管理";
        aa2.NavigateUrl = "~/Login.aspx";
        Menu1.Items[3].ChildItems.Add(aa2);
           
        



        int a = 0;

        var Menus = from menu in dc.Menus
                    select new
                    {
                        MenuItem_id = menu.MenuItem_id,
                        MenuItem_Name = menu.MenuItem_Name
                    };
        
        foreach (var menu in Menus)
        {
                MenuItem menuitem = new MenuItem();
                menuitem.Enabled = true;
                menuitem.Selectable = true;
                menuitem.Selected = false;
                menuitem.ToolTip = menuitem.Text = menu.MenuItem_Name.Trim();
                menuitem.Value = menu.MenuItem_id.ToString();
                Menu1.Items.Add(menuitem);
                a++;


                MenuItem catergory = new MenuItem();//定义子菜单
                catergory.Text = "类别管理";
                catergory.NavigateUrl = "~/register.aspx";
                Menu1.Items[a+3].ChildItems.Add(catergory);//添加子菜单

                MenuItem aa = new MenuItem();

                aa.Text = menu.MenuItem_Name.ToString();
               
           //string bb=ss.Substring(0,3);
                aa.Text = aa.Text.Trim()+ "管理";
         
                    
               
                aa.NavigateUrl = "~/Login.aspx";
                Menu1.Items[a+3].ChildItems.Add(aa);

        }
       
            
        


        MenuItem link = new MenuItem();
        link.Value = link.ToolTip = link.Text = "链接管理";
        link.NavigateUrl = "../Default.aspx";
        Menu1.Items.Add(link);

        MenuItem password = new MenuItem();
        password.Value = password.ToolTip = password.Text = "密码管理";
        password.NavigateUrl = "../Default.aspx";
        Menu1.Items.Add(password);
        

        dc.Dispose();
    }

    
   
    



   
    protected void Logoff_Click(object sender, EventArgs e)
    {
        Session.Remove("admin");
        Response.Redirect("../Default.aspx");
    }
    protected void NoticeManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Notice.aspx");
    }
    protected void DocumentCategoryManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_DocumentCategory.aspx");
    }
    protected void DocumentManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Document.aspx");
    }
    protected void DownloadManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Download.aspx");
    }
    protected void PasswordManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Password.aspx");
    }
    protected void CollegeConditionManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_CollegeCondition.aspx");
    }
    protected void LawManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Law.aspx");
    }
    protected void MeetingManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Meeting.aspx");
    }
    protected void OrgnizationManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Orgnization.aspx");
    }
    protected void RuleManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Rule.aspx");
    }
    protected void LinkManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Link.aspx");
    }
    protected void New_Button_Click(object sender, EventArgs e)
    {
        Session.Add("OperationType", "New");
        Session.Add("NewsType", "Rule");
        Response.Redirect("NewsEdit.aspx");
    }
    protected void NewsListGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            SQL.SQLHelper.Delete(Convert.ToInt32(((Label)NewsListGridView.Rows[e.RowIndex].FindControl("News_id")).Text));
        }
        catch (Exception ex)
        {
        }
        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        NewsListGridView.DataSource = from news in dc.News
                                      join news_category in dc.News_Categories
                                      on news.News_category equals news_category.Category_id
                                      where news_category.Category_name.Equals("规章制度")
                                      orderby news.Time descending
                                      select new
                                      {
                                          标识 = news.News_id,
                                          标题 = news.Title,
                                          日期 = news.Time.Value.Month + "-" + news.Time.Value.Day
                                      };
        NewsListGridView.DataBind();
        dc.Dispose();

    }
    protected void NewsListGridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Session.Add("OperationType", "Edit");
        Session.Add("News_id", ((Label)NewsListGridView.Rows[e.NewEditIndex].FindControl("News_id")).Text);
        Session.Add("NewsType", "Rule");
        Response.Redirect("NewsEdit.aspx");
    }
}
